package cn.zglbk.generator.utils;

import cn.zglbk.generator.model.ColumnEntity;
import cn.zglbk.generator.model.FileContentEntity;
import cn.zglbk.generator.model.TableEntity;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zglbk.cn
 * @email 1030681978@qq.com
 * @date 2020/10/21 15:56
 */
public class EntityUtils {

    static List<TableEntity>  wrappingTableEntity(List<FileContentEntity> entitys){
        List<TableEntity> list = new ArrayList<>();
        if(entitys != null){
            for (FileContentEntity entity : entitys) {
               list.add(wrappingTableEntityByOne(entity));
            }
        }
        return list;
    }
    private static TableEntity wrappingTableEntityByOne(FileContentEntity entity){
        TableEntity model = new TableEntity();
        model.setTableName(entity.getTableName());
        model.setComments("desc");
        model.setClassName(entity.getClassName());
        model.setColumns(wrappingColumnEntitys(entity));
        return model;
    }
    private static List<ColumnEntity> wrappingColumnEntitys(FileContentEntity entity){
        List<ColumnEntity> model = new ArrayList<>();
        for(int i = 0;i<entity.getAttrNames().length;i++){
            String attrName = entity.getAttrNames()[i];
            attrName = StringUtils.columnToJava(attrName);
            //首字母小写AttrName => attrName
            String attrname = org.apache.commons.lang.StringUtils.uncapitalize(attrName);
            String attrType = entity.getAttrTypes()[i];
            String commons = entity.getCommons()[i];
//            model.add(new ColumnEntity(attrname,
//                    attrType,
//                    commons,attrName));
        }
        return model;
    }

}
